package com.pda.gongpin.ui.setemptyfull;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.pda.gongpin.R;
import com.pda.gongpin.adapter.EmptyAdapter;
import com.pda.gongpin.bean.ChangeStatusRequest;
import com.pda.gongpin.bean.EmptyBean;
import com.pda.gongpin.bean.request.StorageBinQueryRequest;
import com.pda.gongpin.contract.SetEmptyFullContract;
import com.pda.gongpin.dialog.AffirmDialog;
import com.pda.gongpin.presenter.SetEmptyFullPresenter;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.http.POST;

@Route(path = AppActivityKey.SETEMPTYFULLACTIVITY)
public class SetEmptyFullActivity extends BaseMvpActivity<SetEmptyFullPresenter> implements SetEmptyFullContract.View {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_back)
    TextView tvBack;
    @BindView(R.id.et_search)
    EditText etSearch;
    @BindView(R.id.tv_search)
    TextView tvSearch;
    @BindView(R.id.rv_content)
    RecyclerView rvContent;
    EmptyAdapter emptyAdapter;
    @BindView(R.id.ll_search)
    LinearLayout llSearch;

    @Override
    public void setList(List<EmptyBean> list) {
        emptyAdapter.setNewInstance(list);
    }

    @Override
    public void onSuccess() {

    }

    @Override
    public SetEmptyFullPresenter getPresenter() {
        return new SetEmptyFullPresenter();
    }

    @Override
    public int getView() {
        return R.layout.activity_list;
    }

    @Override
    public void initView() {
        tvTitle.setText("置空置满");
        llSearch.setVisibility(View.GONE);
        emptyAdapter = new EmptyAdapter(R.layout.item_empty, new ArrayList<>());
        rvContent.setAdapter(emptyAdapter);
        presenter.emptyList(new StorageBinQueryRequest());
    }

    @Override
    public void initLinsenterner() {
        emptyAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                EmptyBean emptyBean=emptyAdapter.getData().get(position);
                ChangeStatusRequest request=new ChangeStatusRequest();
                request.setStorageBinId(emptyBean.getStorageBinId());
                String title="";
                if (emptyBean.getStorageStatus().equals("10")){
                    request.setStorageStatus("20");
                    title="确定要置满吗？";
                }else {
                    request.setStorageStatus("10");
                    title="确定要置空吗？";
                }
                AffirmDialog dialog=new AffirmDialog(mContext, new AffirmDialog.OnConfrim() {
                    @Override
                    public void onConfrim() {
                        presenter.changeStatus(request);
                    }
                });
                dialog.show(title);
            }
        });
    }

    @Override
    public void getData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.iv_back, R.id.tv_search})
    public void onViewClicked(View view) {
        finishActivity();
        switch (view.getId()) {
            case R.id.iv_back:
                break;
            case R.id.tv_search:
                break;
        }
    }
}
